package com.yh.threadTest.test2;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @ClassName Demo
 * @Description TODO
 * @Author 0715-YuHao
 * @Date 2020/11/11 16:51
 */
public class Demo {

    public static void main(String[] args) {
        ExecutorService service = Executors.newCachedThreadPool();
        //向线程池中执行新的任务
        service.execute(() -> {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "哈哈");
        });
        service.execute(() -> {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "哈哈");
        });
        service.execute(() -> {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "哈哈");
        });
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        service.execute(() -> {
            System.out.println(Thread.currentThread().getName() + "哈哈");
        });
    }
}
